package la.iok.hzsvn.lewin.movie.controller;

import la.iok.hzsvn.lewin.movie.core.Token;
import la.iok.hzsvn.lewin.movie.model.ClueCardGroupParam;
import la.iok.hzsvn.lewin.movie.model.ClueCardGroupVo;
import la.iok.hzsvn.lewin.movie.service.ClueCardGroupService;
import la.iok.hzsvn.lewin.movie.service.ClueCardService;
import la.iok.hzsvn.share.response.ListDataResponse;
import la.iok.hzsvn.share.response.OperatorResponse;
import la.iok.hzsvn.share.response.OperatorResponses;
import la.iok.hzsvn.share.response.SingleDataResponse;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("clueCardGroups")
public class ClueCardGroupController {
    private final ClueCardGroupService clueCardGroupService;
    private final ClueCardService clueCardService;

    public ClueCardGroupController(ClueCardGroupService clueCardGroupService,
                                   ClueCardService clueCardService) {
        this.clueCardGroupService = clueCardGroupService;
        this.clueCardService = clueCardService;
    }

    /**
     * 保存分组
     * @param token 操作用户
     * @param id 剧本id
     * @param param 分组信息
     * @return 操作结果及新保存的分组id
     */
    @PostMapping("movie/{id}")
    public SingleDataResponse<Long> save(@RequestHeader Token token, @PathVariable Long id, @RequestBody ClueCardGroupParam param){
        return new SingleDataResponse<>(clueCardGroupService.save(token,id,param));
    }

    /**
     * 修改线索分组信息
     * @param token 操作用户
     * @param id 线索分组id
     * @param param 线索分组信息
     * @return 操作结果
     */
    @PutMapping("{id}")
    public OperatorResponse update(@RequestHeader Token token, @PathVariable Long id, @RequestBody ClueCardGroupParam param) {
        clueCardGroupService.update(token,id,param);
        return OperatorResponses.success();
    }

    /**
     * 删除线索分组
     * @param token 操作用户
     * @param id 线索分组id
     * @return 操作结果
     */
    @DeleteMapping("{id}")
    public OperatorResponse delete(@RequestHeader Token token, @PathVariable Long id){
        clueCardService.deleteGroup(token,id);
        return OperatorResponses.success();
    }

    /**
     * 查询剧本的所有线索分组
     * @param token 操作用户
     * @param id 剧本id
     * @return 线索分组列表
     */
    @GetMapping("movie/{id}")
    public ListDataResponse<ClueCardGroupVo> scenes(@RequestHeader Token token, @PathVariable Long id){
        return new ListDataResponse<>(clueCardGroupService.clueCardGroups(token,id));
    }
}
